package axdoc.done;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.redis.JedisService;

import axdoc.rule.MessageHandleFacotry;
import axdoc.util.StringUtils;

public class ThreadRunnable implements Runnable {

	private static Logger logger = LoggerFactory.getLogger(ThreadRunnable.class);

	JedisService jedisService;

	MessageHandleFacotry messageHandleFacotry;

	public ThreadRunnable(JedisService jedisService, MessageHandleFacotry messageHandleFacotry) {
		this.jedisService = jedisService;
		this.messageHandleFacotry = messageHandleFacotry;
	}

	@Override
	public void run() {
		logger.info("[守护线程启动][------][" + Thread.currentThread().getName() + "]");
		while (true) {
			try {
				String json = jedisService.pop("test_activity_message");
				logger.info("[守护线程启动][取得消息][" + json + "]");
				if (StringUtils.isNotBlank(json)) {
					messageHandleFacotry.done(json);
				} else {
					Thread.sleep(10000);
				}
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

	public JedisService getJedisService() {
		return jedisService;
	}

	public void setJedisService(JedisService jedisService) {
		this.jedisService = jedisService;
	}

	public MessageHandleFacotry getMessageHandleFacotry() {
		return messageHandleFacotry;
	}

	public void setMessageHandleFacotry(MessageHandleFacotry messageHandleFacotry) {
		this.messageHandleFacotry = messageHandleFacotry;
	}

}
